package com.sh.business.service.facade;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import com.aizuda.snailjob.client.job.core.enums.AllocationAlgorithmEnum;
import com.aizuda.snailjob.client.job.core.enums.TriggerTypeEnum;
import com.aizuda.snailjob.client.job.core.openapi.SnailJobOpenApi;
import com.aizuda.snailjob.common.core.enums.JobBlockStrategyEnum;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sh.business.config.RabbitmqSender;
import com.sh.business.domain.*;
import com.sh.business.domain.dto.Bonus;
import com.sh.business.domain.vo.ConfigVo;
import com.sh.business.mapper.*;
import com.sh.business.service.IConfigService;
import com.sh.common.core.enums.*;
import com.sh.common.core.utils.DateUtils;
import com.sh.common.core.utils.SpringUtils;
import com.sh.common.core.utils.StreamUtils;
import com.sh.common.core.utils.StringUtils;
import com.sh.system.service.ISysConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;

import static com.sh.common.core.constant.BusinessConstants.*;
import static com.sh.common.core.constant.SZPNConstants.*;


/**
 * @author dongGe_zzz
 * @date 2024-09-25 14:16
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class UserServiceFacade {

    private final UserMapper userMapper;
    private final UserFundDetailMapper userFundDetailMapper;
    private final UserInvestMapper investMapper;
    private final UserOutInvestMapper outInvestMapper;
    private final UserFoundServiceFacade userFoundServiceFacade;
    private final MiningMapper miningMapper;
    private final ISysConfigService iSysConfigService;
    private final IConfigService iConfigService;
    private final RabbitmqSender rabbitmqSender;
    private final SzpnConfigMapper szpnConfigMapper;

    /**
     * 处理购买、升级矿机、复投
     * @param txHash
     */
    public void handleInvestNotify(String txHash) {
        UserInvest invest = investMapper.queryByTxHash(txHash);

        User user = userMapper.selectById(invest.getUserId());

        List<Long> ancestorList = StringUtils.str2List(user.getAncestors(), StringUtils.SEPARATOR, false, false)
            .stream().map(Long::parseLong).toList();
        List<User> ancestorUserList = userMapper.selectBatchIds(ancestorList);
        // 翻转、按照最近的在前
        Collections.reverse(ancestorUserList);

        // 发放usdt动态级差奖励
        usdtDynamics(ancestorUserList, invest, user);

        // 团队业绩奖励
        ancestorUserList.forEach(currentUser -> {
            userFoundServiceFacade.changeUserFound(currentUser.getUserId(), UserFoundEnum.TEAM_ACHIEVEMENT, TransferFlagEnum.TRANSFER_IN, invest.getAmount());
        });

        // 增加业绩后，再查询一次
        ancestorUserList = userMapper.selectBatchIds(StreamUtils.toList(ancestorUserList, User::getUserId));
        // 翻转、按照最近的在前
        Collections.reverse(ancestorUserList);

        // 处理用户等级
        // 增加自己
        ancestorUserList.addFirst(user);
        handleSzpnUserLevel(StreamUtils.toList(ancestorUserList, User::getUserId));

        // 发送24小时后执行szpn动态奖励
        // rabbitmqSender.sendDailyDynamicsTtlMsg(invest.getOrderSn());
        createCornJob(invest);
    }

    private void createCornJob(UserInvest invest) {
        UserInvest update = new UserInvest();
        update.setId(invest.getId());

        // 获取createTime的时分秒
        Date createTime = invest.getCreateTime();
        System.out.println("orderSn:" + invest.getOrderSn() + ",时间：" + createTime);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(createTime);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);

        // 构建cron表达式，每天执行
        String cronExpression = String.format("%d %d %d * * ?", second, minute, hour);

        Long jobId = SnailJobOpenApi.addClusterJob()
                .setRouteKey(AllocationAlgorithmEnum.ROUND)
                .setJobName(invest.getOrderSn() + "每日动态")
                .setExecutorInfo("DailyDynamicSzpnAnnoJobExecutor")
                .setExecutorTimeout(120)
                .setDescription("add")
                .setBlockStrategy(JobBlockStrategyEnum.DISCARD)
                .setMaxRetryTimes(1)
                .setTriggerType(TriggerTypeEnum.CRON)
                .setTriggerInterval(cronExpression)
                .addArgsStr("orderSn", invest.getOrderSn())
                .setRetryInterval(3)
                .execute();
        update.setJobId(jobId);

        int result = investMapper.updateById(update);
        if (result > 0) {
            log.info("订单：" + invest.getOrderSn() + ",创建任务成功，任务id：" + jobId);
        } else {
            log.error("订单：" + invest.getOrderSn() + ",创建任务失败");
        }
    }

    /**
     * 处理购买、升级矿机、复投 -- 补发
     * @param txHash
     */
    public void handleInvestNotifyResend(String txHash) {
        UserInvest invest = investMapper.queryByTxHash(txHash);

        User user = userMapper.selectById(invest.getUserId());

        System.out.println(user.getAncestors());

        List<Long> ancestorList = StringUtils.str2List(user.getAncestors(), StringUtils.SEPARATOR, false, false)
                .stream().map(Long::parseLong).toList();
        List<User> ancestorUserList = userMapper.selectBatchIds(ancestorList);

        System.out.println(StreamUtils.toList(ancestorUserList, User::getUserId));

        // 翻转、按照最近的在前
        Collections.reverse(ancestorUserList);

        System.out.println(StreamUtils.toList(ancestorUserList, User::getUserId));

        ancestorList.forEach(System.out::println);
        // 发放usdt动态级差奖励
        usdtDynamics(ancestorUserList, invest, user);

//        // 团队业绩奖励
//        ancestorUserList.forEach(currentUser -> {
//            userFoundServiceFacade.changeUserFound(currentUser.getUserId(), UserFoundEnum.TEAM_ACHIEVEMENT, TransferFlagEnum.TRANSFER_IN, invest.getAmount());
//        });
//
//        // 增加业绩后，再查询一次
//        ancestorUserList = userMapper.selectBatchIds(StreamUtils.toList(ancestorUserList, User::getUserId));
//        // 翻转、按照最近的在前
//        Collections.reverse(ancestorUserList);
//
//        // 处理用户等级
//        // 增加自己
//        ancestorUserList.addFirst(user);
//        handleSzpnUserLevel(StreamUtils.toList(ancestorUserList, User::getUserId));
//
//        // 发送24小时后执行szpn动态奖励
//        rabbitmqSender.sendDailyDynamicsTtlMsg(invest.getOrderSn());
    }

    /**
     * 动态usdt级差奖励
     *//*
    public void usdtDynamics(List<User> ancestorUserList, UserInvest userInvest) {
        // 当前奖励级别
        Integer currentLevel = UserLevelEnum.NORMAL.getCode();
        // 当前奖励比例
        BigDecimal currentRatio = BigDecimal.ZERO;

        Map<Integer, SzpnConfig> szpnConfigMap = StreamUtils.toMap(szpnConfigMapper.selectList(), SzpnConfig::getUserLevel, Function.identity());

        for (User currentUser : ancestorUserList) {
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V1.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(userInvest.getAmount(), szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getUsdtDynamics()),
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V2.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getUsdtDynamics(), currentRatio)),
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V3.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getUsdtDynamics(), currentRatio)),
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V4.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getUsdtDynamics(), currentRatio)),
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V5.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getUsdtDynamics(), currentRatio)),
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V6.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getUsdtDynamics(), currentRatio)),
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V7.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getUsdtDynamics(), currentRatio)),
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V8.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getUsdtDynamics(), currentRatio)),
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V9.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getUsdtDynamics(), currentRatio)),
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V10.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getUsdtDynamics(), currentRatio)),
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V11.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V12.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V13.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V14.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V15.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getUsdtDynamics();
            }
        }
    }*/

    /**
     * 动态usdt级差奖励
     */
    public void usdtDynamics(List<User> ancestorUserList, UserInvest userInvest, User user) {

        User currentUser = userMapper.selectById(user.getParentId());

        // 当前奖励级别
        Integer currentLevel = UserLevelEnum.NORMAL.getCode();
        // 当前奖励比例
        BigDecimal currentRatio = BigDecimal.ZERO;

        Map<Integer, SzpnConfig> szpnConfigMap = StreamUtils.toMap(szpnConfigMapper.selectList(), SzpnConfig::getUserLevel, Function.identity());

        while (currentUser != null && currentUser.getUserId() != 10L) {
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V1.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getUsdtDynamics()),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V2.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V3.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V4.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V5.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V6.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V7.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V8.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V9.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V10.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V11.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V12.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V13.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V14.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getUsdtDynamics();
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V15.getCode())) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.USDT,
                        TransferFlagEnum.TRANSFER_IN,
                        NumberUtil.mul(userInvest.getAmount(), NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getUsdtDynamics(), currentRatio)),
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getUsdtDynamics();
            }
            currentUser = userMapper.selectById(currentUser.getParentId());
        }

    }

    /**
     * 动态szpn级差奖励
     */
    public void szpnDynamicsOut(String orderSn) {
        UserOutInvest userInvest = outInvestMapper.queryByOrderSn(orderSn);
        if (ObjectUtil.isNull(userInvest)) {
            return;
        }
        User user = userMapper.selectById(userInvest.getUserId());

        List<Long> ancestorList = StringUtils.str2List(user.getAncestors(), StringUtils.SEPARATOR, false, false)
            .stream().map(Long::parseLong).toList();
        List<User> ancestorUserList = userMapper.selectBatchIds(ancestorList);
        // 翻转、按照最近的在前
        Collections.reverse(ancestorUserList);

        BigDecimal miningSzpnRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.mining.szpn.ratio"));
        BigDecimal mingingSzpnAmount = NumberUtil.mul(NumberUtil.div(NumberUtil.mul(userInvest.getAmount(), BigDecimal.TEN), new BigDecimal("10000")), miningSzpnRatio);

        Map<Integer, SzpnConfig> szpnConfigMap = StreamUtils.toMap(szpnConfigMapper.selectList(), SzpnConfig::getUserLevel, Function.identity());

        // 当前奖励级别
        Integer currentLevel = SzpnUserLevelEnum.NORMAL.getCode();
        // 当前奖励比例
        BigDecimal currentRatio = BigDecimal.ZERO;
        // 平级奖励次数
        int sameLevelTimes = 0;
        // 当前平级奖励金额
        BigDecimal currentAmount = BigDecimal.ZERO;

        BigDecimal sendTotalAmount = BigDecimal.ZERO;

        for (User currentUser : ancestorUserList) {
            if (sameLevelTimes > 0
                && currentUser.getUserLevel() > SzpnUserLevelEnum.NORMAL.getCode()
                && ObjectUtil.equals(currentUser.getUserLevel(), currentLevel)) {
                currentAmount = NumberUtil.mul(currentAmount, new BigDecimal("0.1")).setScale(6, RoundingMode.DOWN);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.LEVEL_REWARD.getCode().toString(),
                    null);
                sameLevelTimes--;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }

            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V1.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getSzpnDynamics());
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V2.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V3.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V4.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V5.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V6.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V7.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V8.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V9.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V10.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V11.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V12.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V13.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V14.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V15.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
        }


        // 动态静态 扣除szpn
        userFoundServiceFacade.modifyUserFound(DYNAMIC_AND_STATIC_ID,
            userInvest.getOrderSn(),
            null,
            UserFoundEnum.AVAILABLE_SZPN,
            TransferFlagEnum.TRANSFER_OUT,
            sendTotalAmount,
            TransferDescEnum.DYNAMIC_AND_STATIC.getCode().toString(),
            null);

        // 发送24小时后执行szpn动态奖励 - 每日循环执行
        rabbitmqSender.sendDailyDynamicsOutTtlMsg(userInvest.getOrderSn(), null);
    }

    /**
     * 动态szpn级差奖励
     */
    public void szpnDynamics(String orderSn) {
        UserInvest userInvest = investMapper.queryByOrderSn(orderSn);
        if (ObjectUtil.isNull(userInvest)) {
            return;
        }
        User user = userMapper.selectById(userInvest.getUserId());

        List<Long> ancestorList = StringUtils.str2List(user.getAncestors(), StringUtils.SEPARATOR, false, false)
            .stream().map(Long::parseLong).toList();
        List<User> ancestorUserList = userMapper.selectBatchIds(ancestorList);
        // 翻转、按照最近的在前
        Collections.reverse(ancestorUserList);

        BigDecimal miningSzpnRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.mining.szpn.ratio"));
        BigDecimal mingingSzpnAmount = NumberUtil.mul(NumberUtil.div(NumberUtil.mul(userInvest.getAmount(), BigDecimal.TEN), new BigDecimal("10000")), miningSzpnRatio);

        Map<Integer, SzpnConfig> szpnConfigMap = StreamUtils.toMap(szpnConfigMapper.selectList(), SzpnConfig::getUserLevel, Function.identity());

        // 当前奖励级别
        Integer currentLevel = SzpnUserLevelEnum.NORMAL.getCode();
        // 当前奖励比例
        BigDecimal currentRatio = BigDecimal.ZERO;
        // 平级奖励次数
        int sameLevelTimes = 0;
        // 当前平级奖励金额
        BigDecimal currentAmount = BigDecimal.ZERO;

        BigDecimal sendTotalAmount = BigDecimal.ZERO;

        User currentUser = userMapper.selectById(user.getParentId());

        while (currentUser != null && currentUser.getUserId() != 10L) {
            if (sameLevelTimes > 0
                && currentUser.getUserLevel() > SzpnUserLevelEnum.NORMAL.getCode()
                && ObjectUtil.equals(currentUser.getUserLevel(), currentLevel)) {
                currentAmount = NumberUtil.mul(currentAmount, new BigDecimal("0.1")).setScale(6, RoundingMode.DOWN);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.LEVEL_REWARD.getCode().toString(),
                    null);
                sameLevelTimes--;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }

            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V1.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getSzpnDynamics());
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V2.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V3.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V4.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V5.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V6.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V7.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V8.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V9.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V10.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    userInvest.getOrderSn(),
                    userInvest.getTxHash(),
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    currentAmount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V11.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        currentAmount,
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V12.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        currentAmount,
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V13.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        currentAmount,
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V14.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        currentAmount,
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }
            if (currentUser.getUserLevel() > currentLevel
                    && ObjectUtil.equals(currentUser.getUserLevel(), SzpnUserLevelEnum.V15.getCode())) {
                currentAmount = NumberUtil.mul(mingingSzpnAmount, NumberUtil.sub(szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getSzpnDynamics(), currentRatio));
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                        userInvest.getOrderSn(),
                        userInvest.getTxHash(),
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        currentAmount,
                        TransferDescEnum.TEAM_REWARD.getCode().toString(),
                        null);
                currentLevel = currentUser.getUserLevel();
                currentRatio = szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getSzpnDynamics();
                sameLevelTimes = 3;
                sendTotalAmount = NumberUtil.add(sendTotalAmount, currentAmount);
            }

            currentUser = userMapper.selectById(currentUser.getParentId());
        }


        // 动态静态 扣除szpn
        userFoundServiceFacade.modifyUserFound(DYNAMIC_AND_STATIC_ID,
                userInvest.getOrderSn(),
                userInvest.getTxHash(),
                UserFoundEnum.AVAILABLE_SZPN,
                TransferFlagEnum.TRANSFER_OUT,
                sendTotalAmount,
                TransferDescEnum.DYNAMIC_AND_STATIC.getCode().toString(),
                null);

        // 发送24小时后执行szpn动态奖励 - 每日循环执行 todo:改成了定时任务
        //rabbitmqSender.sendDailyDynamicsTtlMsg(userInvest.getOrderSn());
    }



    /*public void handleInvestNotify(String txHash) {
        UserInvest invest = investMapper.queryByTxHash(txHash);
        Mining mining = miningMapper.queryByPrice(invest.getAmount());
        ConfigVo configVo = iConfigService.queryById(1L);

        User user = userMapper.selectById(invest.getUserId());
        User directPushUser = userMapper.queryDirectPush(user.getUserId());
        List<Long> ancestorList = StringUtils.str2List(user.getAncestors(), StringUtils.SEPARATOR, false, false)
            .stream().map(Long::parseLong).toList();
        List<User> ancestorUserList = userMapper.selectBatchIds(ancestorList);
        // 翻转、按照最近的在前
        Collections.reverse(ancestorUserList);

        // 总算力
        BigDecimal computility = mining.getComputility();
        boolean ordinary = mining.getPrice().compareTo(SPECIAL_AMOUNT) < 0;

        BigDecimal directPushRatio = ordinary ? configVo.getOrdinary().getDirectPushRatio() : configVo.getSpecial().getDirectPushRatio();
        BigDecimal directPushCustomizeRatio = ordinary ? configVo.getOrdinary().getDirectPushCustomizeRatio() : configVo.getSpecial().getDirectPushCustomizeRatio();
        BigDecimal indirectPushRatio = ordinary ? configVo.getOrdinary().getIndirectPushRatio() : configVo.getSpecial().getIndirectPushRatio();
        BigDecimal agentRatio = ordinary ? configVo.getOrdinary().getAgentRatio() : configVo.getSpecial().getAgentRatio();
        BigDecimal districtAgentRatio = ordinary ? configVo.getOrdinary().getDistrictAgentRatio() : configVo.getSpecial().getDistrictAgentRatio();
        BigDecimal countyAgentRatio = ordinary ? configVo.getOrdinary().getCountyAgentRatio() : configVo.getSpecial().getCountyAgentRatio();
        BigDecimal cityAgentRatio = ordinary ? configVo.getOrdinary().getCityAgentRatio() : configVo.getSpecial().getCityAgentRatio();
        BigDecimal provincialAgentRatio = ordinary ? configVo.getOrdinary().getProvincialAgentRatio() : configVo.getSpecial().getProvincialAgentRatio();
        BigDecimal nationalAgentRatio = ordinary ? configVo.getOrdinary().getNationalAgentRatio() : configVo.getSpecial().getNationalAgentRatio();
        BigDecimal globalAgentRatio = ordinary ? configVo.getOrdinary().getGlobalAgentRatio() : configVo.getSpecial().getGlobalAgentRatio();

        BigDecimal sameLevelRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.same.level.ratio"));

        // 1、usdt - 分配池
        usdtAllocationExtracted(invest);

        // 2、直推、间推算力奖励及增加直推业绩
        directAndIndirectPushextracted(directPushUser, invest, computility, directPushRatio, indirectPushRatio);

        // 额外直推自定义奖励
        userFoundServiceFacade.modifyUserFound(directPushUser.getUserId(),
            invest.getOrderSn(),
            invest.getTxHash(),
            UserFoundEnum.USDT,
            TransferFlagEnum.TRANSFER_IN,
            NumberUtil.mul(mining.getPrice(), directPushCustomizeRatio),
            TransferDescEnum.PURCHASE_MINING_DIRECT_PUSH_CUSTOMIZE.getCode().toString(),
            null);

        // 3、团队业绩奖励
        ancestorUserList.forEach(currentUser -> {
            userFoundServiceFacade.changeUserFound(currentUser.getUserId(), UserFoundEnum.TEAM_ACHIEVEMENT, TransferFlagEnum.TRANSFER_IN, invest.getAmount());
        });

        // 增加业绩后，再查询一次
        ancestorUserList = userMapper.selectBatchIds(StreamUtils.toList(ancestorUserList, User::getUserId));
        // 翻转、按照最近的在前
        Collections.reverse(ancestorUserList);

        // 4、代理算力级差、平级奖励
        computilityExtracted(ancestorUserList, invest, sameLevelRatio, mining, agentRatio, districtAgentRatio, countyAgentRatio, cityAgentRatio, provincialAgentRatio, nationalAgentRatio, globalAgentRatio);

        // 5、市场津贴
        usdtExtracted(ancestorUserList, mining, invest);

        // 6、处理用户等级
        // 增加自己
        ancestorUserList.addFirst(user);
        handleUserLevel(ancestorUserList, directPushUser);
    }*/

    /**
     * 补发奖励 - 172 usdt
     */
    public void reissueUsdtInvestNotify() {
        List<UserInvest> userInvestList = investMapper.query172List();
        for (UserInvest invest : userInvestList) {
            Mining mining = miningMapper.queryByPrice(invest.getAmount());
            ConfigVo configVo = iConfigService.queryById(1L);

            User user = userMapper.selectById(invest.getUserId());
            User directPushUser = userMapper.queryDirectPush(user.getUserId());
            List<Long> ancestorList = StringUtils.str2List(user.getAncestors(), StringUtils.SEPARATOR, false, false)
                    .stream().map(Long::parseLong).toList();
            List<User> ancestorUserList = userMapper.selectBatchIds(ancestorList);
            // 翻转、按照最近的在前
            Collections.reverse(ancestorUserList);

            // 总算力
            BigDecimal computility = mining.getComputility();
            boolean ordinary = mining.getPrice().compareTo(SPECIAL_AMOUNT) < 0;

            BigDecimal directPushRatio = ordinary ? configVo.getOrdinary().getDirectPushRatio() : configVo.getSpecial().getDirectPushRatio();
            BigDecimal directPushCustomizeRatio = ordinary ? configVo.getOrdinary().getDirectPushCustomizeRatio() : configVo.getSpecial().getDirectPushCustomizeRatio();
            BigDecimal indirectPushRatio = ordinary ? configVo.getOrdinary().getIndirectPushRatio() : configVo.getSpecial().getIndirectPushRatio();
            BigDecimal agentRatio = ordinary ? configVo.getOrdinary().getAgentRatio() : configVo.getSpecial().getAgentRatio();
            BigDecimal districtAgentRatio = ordinary ? configVo.getOrdinary().getDistrictAgentRatio() : configVo.getSpecial().getDistrictAgentRatio();
            BigDecimal countyAgentRatio = ordinary ? configVo.getOrdinary().getCountyAgentRatio() : configVo.getSpecial().getCountyAgentRatio();
            BigDecimal cityAgentRatio = ordinary ? configVo.getOrdinary().getCityAgentRatio() : configVo.getSpecial().getCityAgentRatio();
            BigDecimal provincialAgentRatio = ordinary ? configVo.getOrdinary().getProvincialAgentRatio() : configVo.getSpecial().getProvincialAgentRatio();
            BigDecimal nationalAgentRatio = ordinary ? configVo.getOrdinary().getNationalAgentRatio() : configVo.getSpecial().getNationalAgentRatio();
            BigDecimal globalAgentRatio = ordinary ? configVo.getOrdinary().getGlobalAgentRatio() : configVo.getSpecial().getGlobalAgentRatio();

            BigDecimal sameLevelRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.same.level.ratio"));

            // 1、usdt - 分配池
            //usdtAllocationExtracted(invest);

            // 2、直推、间推算力奖励及增加直推业绩
            //directAndIndirectPushextracted(directPushUser, invest, computility, directPushRatio, indirectPushRatio);

            // 额外直推自定义奖励
            /*userFoundServiceFacade.modifyUserFound(directPushUser.getUserId(),
                invest.getOrderSn(),
                invest.getTxHash(),
                UserFoundEnum.USDT,
                TransferFlagEnum.TRANSFER_IN,
                NumberUtil.mul(mining.getPrice(), directPushCustomizeRatio),
                TransferDescEnum.PURCHASE_MINING_DIRECT_PUSH_CUSTOMIZE.getCode().toString(),
                null);*/

            // 3、团队业绩奖励
            /*ancestorUserList.forEach(currentUser -> {
                userFoundServiceFacade.changeUserFound(currentUser.getUserId(), UserFoundEnum.TEAM_ACHIEVEMENT, TransferFlagEnum.TRANSFER_IN, invest.getAmount());
            });*/

            // 增加业绩后，再查询一次
            //ancestorUserList = userMapper.selectBatchIds(StreamUtils.toList(ancestorUserList, User::getUserId));
            // 翻转、按照最近的在前
            //Collections.reverse(ancestorUserList);

            // 4、代理算力级差、平级奖励
            //computilityExtracted(ancestorUserList, invest, sameLevelRatio, mining, agentRatio, districtAgentRatio, countyAgentRatio, cityAgentRatio, provincialAgentRatio, nationalAgentRatio, globalAgentRatio);

            // 5、市场津贴
            usdtExtracted172(ancestorUserList, mining, invest);

            // 6、处理用户等级
            // 增加自己
            //ancestorUserList.addFirst(user);
            //handleUserLevel(ancestorUserList, directPushUser);
        }
    }

    /**
     * 补发奖励
     */
    public void reissueInvestNotify() {
        List<UserInvest> userInvestList = investMapper.selectList(Wrappers.<UserInvest>lambdaQuery().ge(UserInvest::getCreateTime, "2024-11-30 23:07:12").orderByAsc(UserInvest::getCreateTime));
        for (UserInvest invest : userInvestList) {
            Mining mining = miningMapper.queryByPrice(invest.getAmount());
            ConfigVo configVo = iConfigService.queryById(1L);

            User user = userMapper.selectById(invest.getUserId());
            User directPushUser = userMapper.queryDirectPush(user.getUserId());
            List<Long> ancestorList = StringUtils.str2List(user.getAncestors(), StringUtils.SEPARATOR, false, false)
                .stream().map(Long::parseLong).toList();
            List<User> ancestorUserList = userMapper.selectBatchIds(ancestorList);
            // 翻转、按照最近的在前
            Collections.reverse(ancestorUserList);

            // 总算力
            BigDecimal computility = mining.getComputility();
            boolean ordinary = mining.getPrice().compareTo(SPECIAL_AMOUNT) < 0;

            BigDecimal directPushRatio = ordinary ? configVo.getOrdinary().getDirectPushRatio() : configVo.getSpecial().getDirectPushRatio();
            BigDecimal directPushCustomizeRatio = ordinary ? configVo.getOrdinary().getDirectPushCustomizeRatio() : configVo.getSpecial().getDirectPushCustomizeRatio();
            BigDecimal indirectPushRatio = ordinary ? configVo.getOrdinary().getIndirectPushRatio() : configVo.getSpecial().getIndirectPushRatio();
            BigDecimal agentRatio = ordinary ? configVo.getOrdinary().getAgentRatio() : configVo.getSpecial().getAgentRatio();
            BigDecimal districtAgentRatio = ordinary ? configVo.getOrdinary().getDistrictAgentRatio() : configVo.getSpecial().getDistrictAgentRatio();
            BigDecimal countyAgentRatio = ordinary ? configVo.getOrdinary().getCountyAgentRatio() : configVo.getSpecial().getCountyAgentRatio();
            BigDecimal cityAgentRatio = ordinary ? configVo.getOrdinary().getCityAgentRatio() : configVo.getSpecial().getCityAgentRatio();
            BigDecimal provincialAgentRatio = ordinary ? configVo.getOrdinary().getProvincialAgentRatio() : configVo.getSpecial().getProvincialAgentRatio();
            BigDecimal nationalAgentRatio = ordinary ? configVo.getOrdinary().getNationalAgentRatio() : configVo.getSpecial().getNationalAgentRatio();
            BigDecimal globalAgentRatio = ordinary ? configVo.getOrdinary().getGlobalAgentRatio() : configVo.getSpecial().getGlobalAgentRatio();

            BigDecimal sameLevelRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.same.level.ratio"));

            // 1、usdt - 分配池
            //usdtAllocationExtracted(invest);

            // 2、直推、间推算力奖励及增加直推业绩
            //directAndIndirectPushextracted(directPushUser, invest, computility, directPushRatio, indirectPushRatio);

            // 额外直推自定义奖励
            /*userFoundServiceFacade.modifyUserFound(directPushUser.getUserId(),
                invest.getOrderSn(),
                invest.getTxHash(),
                UserFoundEnum.USDT,
                TransferFlagEnum.TRANSFER_IN,
                NumberUtil.mul(mining.getPrice(), directPushCustomizeRatio),
                TransferDescEnum.PURCHASE_MINING_DIRECT_PUSH_CUSTOMIZE.getCode().toString(),
                null);*/

            // 3、团队业绩奖励
            /*ancestorUserList.forEach(currentUser -> {
                userFoundServiceFacade.changeUserFound(currentUser.getUserId(), UserFoundEnum.TEAM_ACHIEVEMENT, TransferFlagEnum.TRANSFER_IN, invest.getAmount());
            });*/

            // 增加业绩后，再查询一次
            //ancestorUserList = userMapper.selectBatchIds(StreamUtils.toList(ancestorUserList, User::getUserId));
            // 翻转、按照最近的在前
            //Collections.reverse(ancestorUserList);

            // 4、代理算力级差、平级奖励
            computilityExtracted(ancestorUserList, invest, sameLevelRatio, mining, agentRatio, districtAgentRatio, countyAgentRatio, cityAgentRatio, provincialAgentRatio, nationalAgentRatio, globalAgentRatio);

            // 5、市场津贴
            usdtExtracted(ancestorUserList, mining, invest);

            // 6、处理用户等级
            // 增加自己
            ancestorUserList.addFirst(user);
            handleUserLevel(ancestorUserList, directPushUser);
        }
    }


    /**
     * 单独补发172团队usdt奖励
     */
    private void usdtExtracted172(List<User> ancestorUserList, Mining mining, UserInvest invest) {
        // 当前奖励级别
        BigDecimal agentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.agent.usdt.ratio"));
        BigDecimal districtAgentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.district.agent.usdt.ratio"));
        BigDecimal countyAgentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.county.agent.usdt.ratio"));
        BigDecimal cityAgentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.city.agent.usdt.ratio"));
        BigDecimal provincialAgentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.provincial.agent.usdt.ratio"));
        BigDecimal nationalAgentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.national.agent.usdt.ratio"));

        Integer currentLevel = UserLevelEnum.NORMAL.getCode();
        BigDecimal amount = BigDecimal.ZERO;
        // 当前奖励比例
        BigDecimal currentRatio = BigDecimal.ZERO;
        for (User currentUser : ancestorUserList) {
            // 代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V.getCode())) {
                amount = NumberUtil.mul(mining.getPrice(), agentUsdtRatio);
                if (ObjectUtil.equals(currentUser.getUserId(), 172L)) {
                    userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                            invest.getOrderSn(),
                            invest.getTxHash(),
                            UserFoundEnum.USDT,
                            TransferFlagEnum.TRANSFER_IN,
                            amount,
                            TransferDescEnum.TEAM_REWARD.getCode().toString(),
                            null);
                }
                currentLevel = UserLevelEnum.V.getCode();
                currentRatio = agentUsdtRatio;
            }
            // 区代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V1.getCode())) {
                BigDecimal ratio = NumberUtil.sub(districtAgentUsdtRatio, currentRatio);
                amount = NumberUtil.mul(mining.getPrice(), ratio);
                if (ObjectUtil.equals(currentUser.getUserId(), 172L)) {
                    userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                            invest.getOrderSn(),
                            invest.getTxHash(),
                            UserFoundEnum.USDT,
                            TransferFlagEnum.TRANSFER_IN,
                            amount,
                            TransferDescEnum.TEAM_REWARD.getCode().toString(),
                            null);
                }
                currentLevel = UserLevelEnum.V1.getCode();
                currentRatio = districtAgentUsdtRatio;
            }
            // 县代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V2.getCode())) {
                BigDecimal ratio = NumberUtil.sub(countyAgentUsdtRatio, currentRatio);
                amount = NumberUtil.mul(mining.getPrice(), ratio);
                if (ObjectUtil.equals(currentUser.getUserId(), 172L)) {
                    userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                            invest.getOrderSn(),
                            invest.getTxHash(),
                            UserFoundEnum.USDT,
                            TransferFlagEnum.TRANSFER_IN,
                            amount,
                            TransferDescEnum.TEAM_REWARD.getCode().toString(),
                            null);
                }
                currentLevel = UserLevelEnum.V2.getCode();
                currentRatio = countyAgentUsdtRatio;
            }
            // 市代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V3.getCode())) {
                BigDecimal ratio = NumberUtil.sub(cityAgentUsdtRatio, currentRatio);
                amount = NumberUtil.mul(mining.getPrice(), ratio);
                if (ObjectUtil.equals(currentUser.getUserId(), 172L)) {
                    userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                            invest.getOrderSn(),
                            invest.getTxHash(),
                            UserFoundEnum.USDT,
                            TransferFlagEnum.TRANSFER_IN,
                            amount,
                            TransferDescEnum.TEAM_REWARD.getCode().toString(),
                            null);
                }
                currentLevel = UserLevelEnum.V3.getCode();
                currentRatio = cityAgentUsdtRatio;
            }
            // 省代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V4.getCode())) {
                BigDecimal ratio = NumberUtil.sub(provincialAgentUsdtRatio, currentRatio);
                amount = NumberUtil.mul(mining.getPrice(), ratio);
                if (ObjectUtil.equals(currentUser.getUserId(), 172L)) {
                    userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                            invest.getOrderSn(),
                            invest.getTxHash(),
                            UserFoundEnum.USDT,
                            TransferFlagEnum.TRANSFER_IN,
                            amount,
                            TransferDescEnum.TEAM_REWARD.getCode().toString(),
                            null);
                }
                currentLevel = UserLevelEnum.V4.getCode();
                currentRatio = provincialAgentUsdtRatio;
            }
            // 全国代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V5.getCode())) {
                BigDecimal ratio = NumberUtil.sub(nationalAgentUsdtRatio, currentRatio);
                amount = NumberUtil.mul(mining.getPrice(), ratio);
                if (ObjectUtil.equals(currentUser.getUserId(), 172L)) {
                    userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                            invest.getOrderSn(),
                            invest.getTxHash(),
                            UserFoundEnum.USDT,
                            TransferFlagEnum.TRANSFER_IN,
                            amount,
                            TransferDescEnum.TEAM_REWARD.getCode().toString(),
                            null);
                }
                currentLevel = UserLevelEnum.V5.getCode();
                currentRatio = nationalAgentUsdtRatio;
            }
        }
    }

    private void usdtExtracted(List<User> ancestorUserList, Mining mining, UserInvest invest) {
        // 当前奖励级别
        BigDecimal agentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.agent.usdt.ratio"));
        BigDecimal districtAgentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.district.agent.usdt.ratio"));
        BigDecimal countyAgentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.county.agent.usdt.ratio"));
        BigDecimal cityAgentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.city.agent.usdt.ratio"));
        BigDecimal provincialAgentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.provincial.agent.usdt.ratio"));
        BigDecimal nationalAgentUsdtRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.national.agent.usdt.ratio"));

        Integer currentLevel = UserLevelEnum.NORMAL.getCode();
        BigDecimal amount = BigDecimal.ZERO;
        // 当前奖励比例
        BigDecimal currentRatio = BigDecimal.ZERO;
        for (User currentUser : ancestorUserList) {
            // 代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V.getCode())) {
                amount = NumberUtil.mul(mining.getPrice(), agentUsdtRatio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V.getCode();
                currentRatio = agentUsdtRatio;
            }
            // 区代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V1.getCode())) {
                BigDecimal ratio = NumberUtil.sub(districtAgentUsdtRatio, currentRatio);
                amount = NumberUtil.mul(mining.getPrice(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V1.getCode();
                currentRatio = districtAgentUsdtRatio;
            }
            // 县代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V2.getCode())) {
                BigDecimal ratio = NumberUtil.sub(countyAgentUsdtRatio, currentRatio);
                amount = NumberUtil.mul(mining.getPrice(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V2.getCode();
                currentRatio = countyAgentUsdtRatio;
            }
            // 市代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V3.getCode())) {
                BigDecimal ratio = NumberUtil.sub(cityAgentUsdtRatio, currentRatio);
                amount = NumberUtil.mul(mining.getPrice(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V3.getCode();
                currentRatio = cityAgentUsdtRatio;
            }
            // 省代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V4.getCode())) {
                BigDecimal ratio = NumberUtil.sub(provincialAgentUsdtRatio, currentRatio);
                amount = NumberUtil.mul(mining.getPrice(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V4.getCode();
                currentRatio = provincialAgentUsdtRatio;
            }
            // 全国代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V5.getCode())) {
                BigDecimal ratio = NumberUtil.sub(nationalAgentUsdtRatio, currentRatio);
                amount = NumberUtil.mul(mining.getPrice(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.USDT,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V5.getCode();
                currentRatio = nationalAgentUsdtRatio;
            }
        }
    }

    /**
     * 团队算力奖励
     * @param ancestorUserList
     * @param invest
     * @param sameLevelRatio
     * @param mining
     * @param districtAgentRatio
     * @param countyAgentRatio
     * @param cityAgentRatio
     * @param provincialAgentRatio
     * @param nationalAgentRatio
     * @param globalAgentRatio
     */
    private void computilityExtracted(List<User> ancestorUserList, UserInvest invest, BigDecimal sameLevelRatio, Mining mining, BigDecimal agentRatio, BigDecimal districtAgentRatio, BigDecimal countyAgentRatio, BigDecimal cityAgentRatio, BigDecimal provincialAgentRatio, BigDecimal nationalAgentRatio, BigDecimal globalAgentRatio) {
        // 当前奖励级别
        Integer currentLevel = UserLevelEnum.NORMAL.getCode();
        BigDecimal amount = BigDecimal.ZERO;
        // 当前奖励比例
        BigDecimal currentRatio = BigDecimal.ZERO;
        // 是否可以发放平级奖励
        boolean sameLevelEnable = false;
        for (User currentUser : ancestorUserList) {
            // 平级奖励
            if (sameLevelEnable
                && currentUser.getLevel() > UserLevelEnum.NORMAL.getCode()
                && Objects.equals(currentUser.getLevel(), currentLevel)) {
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.COMPUTILITY,
                    TransferFlagEnum.TRANSFER_IN,
                    NumberUtil.mul(amount, sameLevelRatio),
                    TransferDescEnum.LEVEL_REWARD.getCode().toString(),
                    null);
                // 标识当前等级已发放平级奖励。平级只有一级
                sameLevelEnable = false;
            }
            // 代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V.getCode())) {
                amount = NumberUtil.mul(mining.getComputility(), agentRatio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.COMPUTILITY,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V.getCode();
                currentRatio = agentRatio;
                sameLevelEnable = true;
            }
            // 区代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V1.getCode())) {
                BigDecimal ratio = NumberUtil.sub(districtAgentRatio, currentRatio);
                amount = NumberUtil.mul(mining.getComputility(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.COMPUTILITY,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V1.getCode();
                currentRatio = districtAgentRatio;
                sameLevelEnable = true;
            }
            // 县代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V2.getCode())) {
                BigDecimal ratio = NumberUtil.sub(countyAgentRatio, currentRatio);
                amount = NumberUtil.mul(mining.getComputility(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.COMPUTILITY,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V2.getCode();
                currentRatio = countyAgentRatio;
                sameLevelEnable = true;
            }
            // 市代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V3.getCode())) {
                BigDecimal ratio = NumberUtil.sub(cityAgentRatio, currentRatio);
                amount = NumberUtil.mul(mining.getComputility(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.COMPUTILITY,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V3.getCode();
                currentRatio = cityAgentRatio;
                sameLevelEnable = true;
            }
            // 省代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V4.getCode())) {
                BigDecimal ratio = NumberUtil.sub(provincialAgentRatio, currentRatio);
                amount = NumberUtil.mul(mining.getComputility(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.COMPUTILITY,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V4.getCode();
                currentRatio = provincialAgentRatio;
                sameLevelEnable = true;
            }
            // 全国代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V5.getCode())) {
                BigDecimal ratio = NumberUtil.sub(nationalAgentRatio, currentRatio);
                amount = NumberUtil.mul(mining.getComputility(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.COMPUTILITY,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V5.getCode();
                currentRatio = nationalAgentRatio;
                sameLevelEnable = true;
            }
            // 全球代理
            if (currentUser.getLevel() > currentLevel && Objects.equals(currentUser.getLevel(), UserLevelEnum.V6.getCode())) {
                BigDecimal ratio = NumberUtil.sub(globalAgentRatio, currentRatio);
                amount = NumberUtil.mul(mining.getComputility(), ratio);
                userFoundServiceFacade.modifyUserFound(currentUser.getUserId(),
                    invest.getOrderSn(),
                    invest.getTxHash(),
                    UserFoundEnum.COMPUTILITY,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.TEAM_REWARD.getCode().toString(),
                    null);
                currentLevel = UserLevelEnum.V6.getCode();
                currentRatio = globalAgentRatio;
                sameLevelEnable = true;
            }

        }
    }

    /**
     * 直推、间推奖励
     * @param directPushUser
     * @param invest
     * @param computility
     * @param directPushRatio
     * @param indirectPushRatio
     */
    private void directAndIndirectPushextracted(User directPushUser, UserInvest invest, BigDecimal computility, BigDecimal directPushRatio, BigDecimal indirectPushRatio) {
        // 直推奖励
        if (ObjectUtil.isNotNull(directPushUser) && directPushUser.getIsActive()) {
            userFoundServiceFacade.modifyUserFound(directPushUser.getUserId(),
                invest.getOrderSn(),
                invest.getTxHash(),
                UserFoundEnum.COMPUTILITY,
                TransferFlagEnum.TRANSFER_IN,
                NumberUtil.mul(computility, directPushRatio),
                TransferDescEnum.PURCHASE_MINING_DIRECT_PUSH.getCode().toString(),
                null);
        } else {
            log.error("订单编号:{},直推未激活:{}", invest.getOrderSn(),directPushUser.getUserId());
        }
        // 增加直推业绩
        userFoundServiceFacade.changeUserFound(directPushUser.getUserId(),
            UserFoundEnum.DIRECT_PUSH_ACHIEVEMENT,
            TransferFlagEnum.TRANSFER_IN,
            invest.getAmount());
        // 修改直推入金列表
        updateDirectPushDeposit(directPushUser, String.valueOf(invest.getUserId()));

        // 间推奖励
        User user = userMapper.selectById(directPushUser.getParentId());
        if (ObjectUtil.isNotNull(user) && user.getIsActive()) {
            userFoundServiceFacade.modifyUserFound(directPushUser.getParentId(),
                invest.getOrderSn(),
                invest.getTxHash(),
                UserFoundEnum.COMPUTILITY,
                TransferFlagEnum.TRANSFER_IN,
                NumberUtil.mul(computility, indirectPushRatio),
                TransferDescEnum.PURCHASE_MINING_INDIRECT_PUSH.getCode().toString(),
                null);
        } else {
            log.error("订单编号:{},间推未激活:{}", invest.getOrderSn(),directPushUser.getParentId());
        }

    }

    /**
     * 修改直推入金列表
     * @param directPushUser
     * @param userId
     */
    public void updateDirectPushDeposit(User directPushUser, String userId) {
        User updateUser = new User();
        updateUser.setUserId(directPushUser.getUserId());
        if (StringUtils.isBlank(directPushUser.getDirectPushDeposit())) {
            updateUser.setDirectPushDeposit(userId);
            userMapper.updateById(updateUser);
        } else {
            Set<String> directPushDepositSet = StringUtils.str2Set(directPushUser.getDirectPushDeposit(), StringUtils.SEPARATOR);
            if (!directPushDepositSet.contains(userId)) {
                updateUser.setDirectPushDeposit(directPushUser.getDirectPushDeposit() + StringUtils.SEPARATOR + userId);
                userMapper.updateById(updateUser);
            }
        }
    }

    /**
     * usdt 分配
     * @param invest
     */
    private void usdtAllocationExtracted(UserInvest invest) {
        //      算力设备采购：40%
        BigDecimal miningMachineRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.mining.machine.ratio"));
        userFoundServiceFacade.modifyUserFound(MINING_MACHINE_ID,
            invest.getOrderSn(),
            invest.getTxHash(),
            UserFoundEnum.USDT,
            TransferFlagEnum.TRANSFER_IN,
            NumberUtil.mul(invest.getAmount(), miningMachineRatio),
            TransferDescEnum.MINING_MACHINE_ALLOCATION.getCode().toString(),
            null);

        //      市场提成：35%
        BigDecimal marketCommissionRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.market.commission.ratio"));
        userFoundServiceFacade.modifyUserFound(MARKET_COMMISSION_ID,
            invest.getOrderSn(),
            invest.getTxHash(),
            UserFoundEnum.USDT,
            TransferFlagEnum.TRANSFER_IN,
            NumberUtil.mul(invest.getAmount(), marketCommissionRatio),
            TransferDescEnum.MARKET_COMMISSION_ALLOCATION.getCode().toString(),
            null);

        //      运营：6%
        BigDecimal operationRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.operation.ratio"));
        userFoundServiceFacade.modifyUserFound(OPERATION_ID,
            invest.getOrderSn(),
            invest.getTxHash(),
            UserFoundEnum.USDT,
            TransferFlagEnum.TRANSFER_IN,
            NumberUtil.mul(invest.getAmount(), operationRatio),
            TransferDescEnum.OPERATION_ALLOCATION.getCode().toString(),
            null);

        //      基金：10%
        BigDecimal fundRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.fund.ratio"));
        userFoundServiceFacade.modifyUserFound(FUND_ID,
            invest.getOrderSn(),
            invest.getTxHash(),
            UserFoundEnum.USDT,
            TransferFlagEnum.TRANSFER_IN,
            NumberUtil.mul(invest.getAmount(), fundRatio),
            TransferDescEnum.FUND_ALLOCATION.getCode().toString(),
            null);

        //      市场推广：9%
        BigDecimal marketPromotionRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.market.promotion.ratio"));
        userFoundServiceFacade.modifyUserFound(MARKET_PROMOTION_ID,
            invest.getOrderSn(),
            invest.getTxHash(),
            UserFoundEnum.USDT,
            TransferFlagEnum.TRANSFER_IN,
            NumberUtil.mul(invest.getAmount(), marketPromotionRatio),
            TransferDescEnum.MARKET_PROMOTION_ALLOCATION.getCode().toString(),
            null);
    }

    /**
     * 处理用户等级
     * 代理 V     个人算力5000  + 2000 + 团队业绩2万
     * 区代理 V1  个人算力10000 + 3000 + 团队业绩5万
     * 县代理 V2   个人算力20000 + 2个V1  + 团队业绩15万
     * 市代理 V3   个人算力30000 + 2个V2  + 团队业绩50万
     * 省代理 V4  个人算力50000 + 2个V3  + 团队业绩200万
     * 全国代 V5  个人算力80000 + 2个V4  + 团队业绩600万
     * 全球代 V6  个人算力150000 + 2个V5
     */
    public void handleUserLevel(List<User> ancestorUserList, User directPushUser) {

        // 批量处理业绩
        if (CollUtil.isNotEmpty(ancestorUserList)) {

            // 处理用户等级v
            List<User> upLevelVUserList = new ArrayList<>(ancestorUserList.size());
            ancestorUserList.forEach(user -> {

                List<Long> userIds = userMapper.queryVCount(user.getUserId());
                var ref = new Object() {
                    int count = 0;
                };
                if (CollUtil.isNotEmpty(userIds)) {
                    ref.count = userIds.size();
                }

                if (user.getComputility().compareTo(UP_V_SELF_COMPUTILITY) >= 0
                    && ref.count >= 3
                    && user.getTeamAchievement().compareTo(UP_V_TEAM_ACHIEVEMENT) >= 0) {
                    // 满足条件，升级v。备注：当用户身份小于要升级身份时，则升级
                    if (user.getLevel() < UserLevelEnum.V.getCode()) {
                        User updateUser = new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setLevel(UserLevelEnum.V.getCode());
                        upLevelVUserList.add(updateUser);
                    }
                }
            });
            // 升级v用户集合
            if (CollUtil.isNotEmpty(upLevelVUserList)) {
                userMapper.updateBatchById(upLevelVUserList);
            }

            // 处理用户等级v1
            List<User> upLevelV1UserList = new ArrayList<>(ancestorUserList.size());
            ancestorUserList.forEach(user -> {

                List<Long> userIds = userMapper.queryVCount(user.getUserId());
                var ref = new Object() {
                    int count = 0;
                };
                if (CollUtil.isNotEmpty(userIds)) {
                    ref.count = userIds.size();
                }

                if (user.getComputility().compareTo(UP_V1_SELF_COMPUTILITY) >= 0
                    && ref.count >= 3
                    && user.getTeamAchievement().compareTo(UP_V1_TEAM_ACHIEVEMENT) >= 0) {
                    // 满足条件，升级v1。备注：当用户身份小于要升级身份时，则升级
                    if (user.getLevel() < UserLevelEnum.V1.getCode()) {
                        User updateUser = new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setLevel(UserLevelEnum.V1.getCode());
                        upLevelV1UserList.add(updateUser);
                    }
                }
            });
            // 升级v1用户集合
            if (CollUtil.isNotEmpty(upLevelV1UserList)) {
                userMapper.updateBatchById(upLevelV1UserList);
            }



            List<User> allUserList = userMapper.selectList(Wrappers.<User>lambdaQuery().select(User::getUserId, User::getParentId, User::getLevel, User::getTeamAchievement, User::getAncestors));

            // 升级v2、v3
            ancestorUserList.forEach(user -> {

                List<User> directPushList = StreamUtils.filter(allUserList, u -> u.getParentId().equals(user.getUserId()));

                // 升级v6
                if (user.getLevel() < UserLevelEnum.V6.getCode()
                        && user.getComputility().compareTo(UP_V6_SELF_COMPUTILITY) >= 0
                    && hasOverTwoLineLowerLevel(directPushList, UserLevelEnum.V5.getCode())) {
                    User updateUser = new User();
                    updateUser.setUserId(user.getUserId());
                    updateUser.setLevel(UserLevelEnum.V6.getCode());

                    userMapper.updateById(updateUser);
                }
                // 升级v5
                if (user.getLevel() < UserLevelEnum.V5.getCode() && user.getComputility().compareTo(UP_V5_SELF_COMPUTILITY) >= 0
                    && user.getTeamAchievement().compareTo(UP_V5_TEAM_ACHIEVEMENT) >= 0
                    && hasOverTwoLineLowerLevel(directPushList, UserLevelEnum.V4.getCode())) {
                    User updateUser = new User();
                    updateUser.setUserId(user.getUserId());
                    updateUser.setLevel(UserLevelEnum.V5.getCode());

                    userMapper.updateById(updateUser);
                }
                // 升级v4
                if (user.getLevel() < UserLevelEnum.V4.getCode() && user.getComputility().compareTo(UP_V4_SELF_COMPUTILITY) >= 0
                    && user.getTeamAchievement().compareTo(UP_V4_TEAM_ACHIEVEMENT) >= 0
                    && hasOverTwoLineLowerLevel(directPushList, UserLevelEnum.V3.getCode())) {
                    User updateUser = new User();
                    updateUser.setUserId(user.getUserId());
                    updateUser.setLevel(UserLevelEnum.V4.getCode());

                    userMapper.updateById(updateUser);
                }
                // 升级v3
                if (user.getLevel() < UserLevelEnum.V3.getCode() && user.getComputility().compareTo(UP_V3_SELF_COMPUTILITY) >= 0
                    && user.getTeamAchievement().compareTo(UP_V3_TEAM_ACHIEVEMENT) >= 0
                    && hasOverTwoLineLowerLevel(directPushList, UserLevelEnum.V2.getCode())) {
                    User updateUser = new User();
                    updateUser.setUserId(user.getUserId());
                    updateUser.setLevel(UserLevelEnum.V3.getCode());

                    userMapper.updateById(updateUser);
                }
                // 升级v2
                if (user.getLevel() < UserLevelEnum.V2.getCode() && user.getComputility().compareTo(UP_V2_SELF_COMPUTILITY) >= 0
                    && user.getTeamAchievement().compareTo(UP_V2_TEAM_ACHIEVEMENT) >= 0
                    && hasOverTwoLineLowerLevel(directPushList, UserLevelEnum.V1.getCode())) {
                    User updateUser = new User();
                    updateUser.setUserId(user.getUserId());
                    updateUser.setLevel(UserLevelEnum.V2.getCode());

                    userMapper.updateById(updateUser);
                }

            });

        }
    }

    /**
     * 判定伞下是否有2条以上不同线路的指定身份
     * @param directPushList
     * @param level
     * @return
     */
    public boolean hasOverTwoLineLowerLevel(List<User> directPushList, Integer level) {
        List<User> users = StreamUtils.filter(directPushList, u -> u.getLevel() >= level);
        if (users.size() >= NEED_LEVEL_NUMBER) {
            return true;
        }
        AtomicReference<Integer> levelNum = new AtomicReference<>(0);
        directPushList.forEach(user -> {
            List<User> children = userMapper.queryUmbrellaUsers(user.getUserId());
            List<User> filtered = StreamUtils.filter(children, u -> u.getLevel() >= level);
            // 当前直推线路（看成部门）伞下有超过这个身份等级的，就算一个
            if (!filtered.isEmpty()) {
                levelNum.getAndSet(levelNum.get() + 1);
            }
        });

        return levelNum.get() >= NEED_LEVEL_NUMBER;
    }


    /**
     * 每日挖矿产出
     */
    public void mining() {
        Integer miningConfig = Convert.toInt(iSysConfigService.selectConfigByKey("biz.mining.config"));
        log.info("今日产出配置:{}", miningConfig);
        if (miningConfig == 0) {
            return;
        } else if (miningConfig == 1) {
            mingAleo();
        } else if (miningConfig == 2) {
            mingScr();
        } else if (miningConfig == 3) {
            mingSzpn();
        }

    }


    /**
     * 挖矿产出Aleo
     */
    public void mingAleo() {

        BigDecimal miningAleoRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.mining.aleo.ratio"));
        BigDecimal globalComputility = userMapper.queryGlobalComputility();
        if (globalComputility.compareTo(BigDecimal.ZERO) == 0) {
            return;
        }
        // 本次挖矿数量
        BigDecimal currentAmount = NumberUtil.mul(NumberUtil.div(globalComputility, new BigDecimal("10000")), miningAleoRatio);
        List<User> users = userMapper.selectList(Wrappers.<User>lambdaQuery().select(User::getUserId, User::getLevel, User::getSelfAchievement, User::getComputility, User::getHasDividend));
        // 1、分红
        Bonus bonus = iConfigService.queryById(1L).getBonus();
        BigDecimal sendTotalAmount = BigDecimal.ZERO;

        // 市代理
        BigDecimal cityAmount = NumberUtil.mul(currentAmount, bonus.getCityAgentRatio());
        List<Integer> cityLevelList = CollUtil.newArrayList(UserLevelEnum.V3.getCode(), UserLevelEnum.V4.getCode(), UserLevelEnum.V5.getCode());
        List<User> cityMiningAleoList = StreamUtils.filter(users, user -> cityLevelList.contains(user.getLevel()) && user.getHasDividend());
        //
        if (CollUtil.isNotEmpty(cityMiningAleoList)) {
            BigDecimal everyAmount = NumberUtil.div(cityAmount, cityMiningAleoList.size());
            cityMiningAleoList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                    null,
                    null,
                    UserFoundEnum.ALEO,
                    TransferFlagEnum.TRANSFER_IN,
                    everyAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                null,
                null,
                UserFoundEnum.ALEO,
                TransferFlagEnum.TRANSFER_IN,
                cityAmount,
                TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                null);
        }

        // 省代理
        BigDecimal provincialAmount = NumberUtil.mul(currentAmount, bonus.getProvincialAgentRatio());
        List<Integer> provincialLevelList = CollUtil.newArrayList(UserLevelEnum.V4.getCode(), UserLevelEnum.V5.getCode(), UserLevelEnum.V6.getCode());
        List<User> provincialMiningAleoList = StreamUtils.filter(users, user -> provincialLevelList.contains(user.getLevel()) && user.getHasDividend());
        //
        if (CollUtil.isNotEmpty(provincialMiningAleoList)) {
            BigDecimal everyAmount = NumberUtil.div(provincialAmount, provincialMiningAleoList.size());
            provincialMiningAleoList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                    null,
                    null,
                    UserFoundEnum.ALEO,
                    TransferFlagEnum.TRANSFER_IN,
                    everyAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                null,
                null,
                UserFoundEnum.ALEO,
                TransferFlagEnum.TRANSFER_IN,
                provincialAmount,
                TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                null);
        }

        // 全国代理
        BigDecimal nationalAmount = NumberUtil.mul(currentAmount, bonus.getNationalAgentRatio());
        List<Integer> nationalLevelList = CollUtil.newArrayList(UserLevelEnum.V5.getCode(), UserLevelEnum.V6.getCode());
        List<User> nationalMiningAleoList = StreamUtils.filter(users, user -> nationalLevelList.contains(user.getLevel()) && user.getHasDividend());
        //
        if (CollUtil.isNotEmpty(nationalMiningAleoList)) {
            BigDecimal everyAmount = NumberUtil.div(nationalAmount, nationalMiningAleoList.size());
            nationalMiningAleoList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                    null,
                    null,
                    UserFoundEnum.ALEO,
                    TransferFlagEnum.TRANSFER_IN,
                    everyAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                null,
                null,
                UserFoundEnum.ALEO,
                TransferFlagEnum.TRANSFER_IN,
                nationalAmount,
                TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                null);
        }

        // 全球代理
        BigDecimal globalAmount = NumberUtil.mul(currentAmount, bonus.getGlobalAgentRatio());
        List<Integer> globalLevelList = CollUtil.newArrayList(UserLevelEnum.V6.getCode());
        List<User> globalMiningAleoList = StreamUtils.filter(users, user -> globalLevelList.contains(user.getLevel()) && user.getHasDividend());
        //
        if (CollUtil.isNotEmpty(globalMiningAleoList)) {
            BigDecimal everyAmount = NumberUtil.div(globalAmount, globalMiningAleoList.size());
            globalMiningAleoList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                    null,
                    null,
                    UserFoundEnum.ALEO,
                    TransferFlagEnum.TRANSFER_IN,
                    everyAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                null,
                null,
                UserFoundEnum.ALEO,
                TransferFlagEnum.TRANSFER_IN,
                globalAmount,
                TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                null);
        }

        // 2、挖矿 - 按算力加权平分
        //BigDecimal afterRatio = NumberUtil.sub(1, bonus.getCityAgentRatio(), bonus.getProvincialAgentRatio(), bonus.getNationalAgentRatio(), bonus.getGlobalAgentRatio());
        BigDecimal mingAmount = NumberUtil.mul(currentAmount, new BigDecimal("0.9"));

        List<User> miningUserList = StreamUtils.filter(users, user -> user.getComputility().compareTo(BigDecimal.ZERO) > 0);

        miningUserList.forEach(user -> {
            BigDecimal amount = NumberUtil.mul(mingAmount, NumberUtil.div(user.getComputility(), globalComputility));
            userFoundServiceFacade.modifyUserFound(user.getUserId(),
                null,
                null,
                UserFoundEnum.ALEO,
                TransferFlagEnum.TRANSFER_IN,
                amount,
                TransferDescEnum.MINING_REWARD.getCode().toString(),
                null);
        });

    }

    /**
     * 挖矿产出Scr
     */
    public void mingScr() {

        BigDecimal miningScrRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.mining.scr.ratio"));
        BigDecimal globalComputility = userMapper.queryGlobalComputility();
        if (globalComputility.compareTo(BigDecimal.ZERO) == 0) {
            return;
        }
        // 本次挖矿数量
        BigDecimal currentAmount = NumberUtil.mul(NumberUtil.div(globalComputility, new BigDecimal("10000")), miningScrRatio);
        List<User> users = userMapper.selectList(Wrappers.<User>lambdaQuery().select(User::getUserId, User::getLevel, User::getSelfAchievement, User::getComputility));
        // 1、分红
        Bonus bonus = iConfigService.queryById(1L).getBonus();
        BigDecimal sendTotalAmount = BigDecimal.ZERO;

        // 市代理
        BigDecimal cityAmount = NumberUtil.mul(currentAmount, bonus.getCityAgentRatio());
        List<Integer> cityLevelList = CollUtil.newArrayList(UserLevelEnum.V3.getCode(), UserLevelEnum.V4.getCode(), UserLevelEnum.V5.getCode());
        List<User> cityMiningAleoList = StreamUtils.filter(users, user -> cityLevelList.contains(user.getLevel()));
        //
        if (CollUtil.isNotEmpty(cityMiningAleoList)) {
            BigDecimal everyAmount = NumberUtil.div(cityAmount, cityMiningAleoList.size());
            cityMiningAleoList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.SCR,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.SCR,
                    TransferFlagEnum.TRANSFER_IN,
                    cityAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }

        // 省代理
        BigDecimal provincialAmount = NumberUtil.mul(currentAmount, bonus.getProvincialAgentRatio());
        List<Integer> provincialLevelList = CollUtil.newArrayList(UserLevelEnum.V4.getCode(), UserLevelEnum.V5.getCode(), UserLevelEnum.V6.getCode());
        List<User> provincialMiningAleoList = StreamUtils.filter(users, user -> provincialLevelList.contains(user.getLevel()));
        //
        if (CollUtil.isNotEmpty(provincialMiningAleoList)) {
            BigDecimal everyAmount = NumberUtil.div(provincialAmount, provincialMiningAleoList.size());
            provincialMiningAleoList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.SCR,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.SCR,
                    TransferFlagEnum.TRANSFER_IN,
                    provincialAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }

        // 全国代理
        BigDecimal nationalAmount = NumberUtil.mul(currentAmount, bonus.getNationalAgentRatio());
        List<Integer> nationalLevelList = CollUtil.newArrayList(UserLevelEnum.V5.getCode(), UserLevelEnum.V6.getCode());
        List<User> nationalMiningAleoList = StreamUtils.filter(users, user -> nationalLevelList.contains(user.getLevel()));
        //
        if (CollUtil.isNotEmpty(nationalMiningAleoList)) {
            BigDecimal everyAmount = NumberUtil.div(nationalAmount, nationalMiningAleoList.size());
            nationalMiningAleoList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.SCR,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.SCR,
                    TransferFlagEnum.TRANSFER_IN,
                    nationalAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }

        // 全球代理
        BigDecimal globalAmount = NumberUtil.mul(currentAmount, bonus.getGlobalAgentRatio());
        List<Integer> globalLevelList = CollUtil.newArrayList(UserLevelEnum.V6.getCode());
        List<User> globalMiningAleoList = StreamUtils.filter(users, user -> globalLevelList.contains(user.getLevel()));
        //
        if (CollUtil.isNotEmpty(globalMiningAleoList)) {
            BigDecimal everyAmount = NumberUtil.div(globalAmount, globalMiningAleoList.size());
            globalMiningAleoList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.SCR,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.SCR,
                    TransferFlagEnum.TRANSFER_IN,
                    globalAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }

        // 2、挖矿 - 按算力加权平分
        //BigDecimal afterRatio = NumberUtil.sub(1, bonus.getCityAgentRatio(), bonus.getProvincialAgentRatio(), bonus.getNationalAgentRatio(), bonus.getGlobalAgentRatio());
        BigDecimal mingAmount = NumberUtil.mul(currentAmount, new BigDecimal("0.9"));

        List<User> miningUserList = StreamUtils.filter(users, user -> user.getComputility().compareTo(BigDecimal.ZERO) > 0);

        miningUserList.forEach(user -> {
            BigDecimal amount = NumberUtil.mul(mingAmount, NumberUtil.div(user.getComputility(), globalComputility));
            userFoundServiceFacade.modifyUserFound(user.getUserId(),
                    null,
                    null,
                    UserFoundEnum.SCR,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.MINING_REWARD.getCode().toString(),
                    null);
        });

    }

    /**
     * 挖矿产出Szpn
     */
    public void mingSzpn() {

        BigDecimal miningSzpnRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.mining.szpn.ratio"));
        BigDecimal globalComputility = userMapper.queryGlobalComputility();
        if (globalComputility.compareTo(BigDecimal.ZERO) == 0) {
            return;
        }
        // 本次挖矿数量
        BigDecimal currentAmount = NumberUtil.mul(NumberUtil.div(globalComputility, new BigDecimal("10000")), miningSzpnRatio);
        List<User> users = userMapper.selectList(Wrappers.<User>lambdaQuery().select(User::getUserId, User::getLevel, User::getUserLevel, User::getNodeFlag, User::getSelfAchievement, User::getComputility, User::getPurchaseComputility));
        // 1、分红

        AtomicReference<BigDecimal> sendTotalAmount = new AtomicReference<>(BigDecimal.ZERO);

        // V11
        BigDecimal cityAmount = NumberUtil.mul(currentAmount, Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.v11.bonus.ratio")));
        List<Integer> v11LevelList = CollUtil.newArrayList(SzpnUserLevelEnum.V11.getCode(), SzpnUserLevelEnum.V12.getCode(), SzpnUserLevelEnum.V13.getCode());
        List<User> v11MiningSzpnList = StreamUtils.filter(users, user -> v11LevelList.contains(user.getUserLevel()) || v11LevelList.contains(user.getNodeFlag()));
        //
        if (CollUtil.isNotEmpty(v11MiningSzpnList)) {
            BigDecimal everyAmount = NumberUtil.div(cityAmount, v11MiningSzpnList.size());
            v11MiningSzpnList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    cityAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }
        sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), cityAmount));

        // v12
        BigDecimal provincialAmount = NumberUtil.mul(currentAmount, Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.v12.bonus.ratio")));
        List<Integer> v12LevelList = CollUtil.newArrayList(SzpnUserLevelEnum.V12.getCode(), SzpnUserLevelEnum.V13.getCode(), SzpnUserLevelEnum.V14.getCode());
        List<User> v12MiningSzpnList = StreamUtils.filter(users, user -> v12LevelList.contains(user.getLevel()) || v12LevelList.contains(user.getNodeFlag()));
        //
        if (CollUtil.isNotEmpty(v12MiningSzpnList)) {
            BigDecimal everyAmount = NumberUtil.div(provincialAmount, v12MiningSzpnList.size());
            v12MiningSzpnList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    provincialAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }
        sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), provincialAmount));

        // v13
        BigDecimal nationalAmount = NumberUtil.mul(currentAmount, Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.v13.bonus.ratio")));
        List<Integer> v13LevelList = CollUtil.newArrayList(SzpnUserLevelEnum.V13.getCode(), SzpnUserLevelEnum.V14.getCode(), SzpnUserLevelEnum.V15.getCode());
        List<User> v13MiningSzpnList = StreamUtils.filter(users, user -> v13LevelList.contains(user.getLevel()) || v13LevelList.contains(user.getNodeFlag()));
        //
        if (CollUtil.isNotEmpty(v13MiningSzpnList)) {
            BigDecimal everyAmount = NumberUtil.div(nationalAmount, v13MiningSzpnList.size());
            v13MiningSzpnList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    nationalAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }
        sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), nationalAmount));

        // v14
        BigDecimal globalAmount = NumberUtil.mul(currentAmount, Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.v14.bonus.ratio")));
        List<Integer> v14LevelList = CollUtil.newArrayList(SzpnUserLevelEnum.V14.getCode(), SzpnUserLevelEnum.V15.getCode());
        List<User> v14MiningSzpnList = StreamUtils.filter(users, user -> v14LevelList.contains(user.getLevel()) || v14LevelList.contains(user.getNodeFlag()));
        //
        if (CollUtil.isNotEmpty(v14MiningSzpnList)) {
            BigDecimal everyAmount = NumberUtil.div(globalAmount, v14MiningSzpnList.size());
            v14MiningSzpnList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    globalAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }
        sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), globalAmount));

        // v15
        BigDecimal v15Amount = NumberUtil.mul(currentAmount, Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.v15.bonus.ratio")));
        List<Integer> v15LevelList = CollUtil.newArrayList(SzpnUserLevelEnum.V15.getCode());
        List<User> v15MiningSzpnList = StreamUtils.filter(users, user -> v15LevelList.contains(user.getLevel()) || v15LevelList.contains(user.getNodeFlag()));
        //
        if (CollUtil.isNotEmpty(v15MiningSzpnList)) {
            BigDecimal everyAmount = NumberUtil.div(v15Amount, v15MiningSzpnList.size());
            v15MiningSzpnList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    v15Amount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }
        sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), v15Amount));

        // 2、挖矿 - 按算力加权平分
        //BigDecimal afterRatio = NumberUtil.sub(1, bonus.getCityAgentRatio(), bonus.getProvincialAgentRatio(), bonus.getNationalAgentRatio(), bonus.getGlobalAgentRatio());
        BigDecimal mingAmount = NumberUtil.mul(currentAmount, new BigDecimal("0.9"));

        List<User> miningUserList = StreamUtils.filter(users, user -> user.getComputility().compareTo(BigDecimal.ZERO) > 0);

        miningUserList.forEach(user -> {
            BigDecimal amount = NumberUtil.mul(mingAmount, NumberUtil.div(user.getComputility(), globalComputility));
            userFoundServiceFacade.modifyUserFound(user.getUserId(),
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    amount,
                    TransferDescEnum.MINING_REWARD.getCode().toString(),
                    null);
            sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), amount));
        });

        // 动态静态 扣除szpn
        userFoundServiceFacade.modifyUserFound(DYNAMIC_AND_STATIC_ID,
                null,
                null,
                UserFoundEnum.AVAILABLE_SZPN,
                TransferFlagEnum.TRANSFER_OUT,
                sendTotalAmount.get(),
                TransferDescEnum.DYNAMIC_AND_STATIC.getCode().toString(),
                null);

    }


    public void mingSzpnResend() {

        BigDecimal miningSzpnRatio = Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.mining.szpn.ratio"));
        BigDecimal globalComputility = userMapper.queryGlobalComputility();
        if (globalComputility.compareTo(BigDecimal.ZERO) == 0) {
            return;
        }
        // 本次挖矿数量
        BigDecimal currentAmount = NumberUtil.mul(NumberUtil.div(globalComputility, new BigDecimal("10000")), miningSzpnRatio);
        List<User> users = userMapper.selectList(Wrappers.<User>lambdaQuery().select(User::getUserId, User::getLevel, User::getUserLevel, User::getNodeFlag, User::getSelfAchievement, User::getComputility, User::getPurchaseComputility));
        // 1、分红

        AtomicReference<BigDecimal> sendTotalAmount = new AtomicReference<>(BigDecimal.ZERO);

        // V11
        BigDecimal cityAmount = NumberUtil.mul(currentAmount, Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.v11.bonus.ratio")));
        List<Integer> v11LevelList = CollUtil.newArrayList(SzpnUserLevelEnum.V11.getCode(), SzpnUserLevelEnum.V12.getCode(), SzpnUserLevelEnum.V13.getCode());
        List<User> v11MiningSzpnList = StreamUtils.filter(users, user -> v11LevelList.contains(user.getUserLevel()) || v11LevelList.contains(user.getNodeFlag()));
        //
        /*if (CollUtil.isNotEmpty(v11MiningSzpnList)) {
            BigDecimal everyAmount = NumberUtil.div(cityAmount, v11MiningSzpnList.size());
            v11MiningSzpnList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    cityAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }*/
        sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), cityAmount));

        // v12
        BigDecimal provincialAmount = NumberUtil.mul(currentAmount, Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.v12.bonus.ratio")));
        List<Integer> v12LevelList = CollUtil.newArrayList(SzpnUserLevelEnum.V12.getCode(), SzpnUserLevelEnum.V13.getCode(), SzpnUserLevelEnum.V14.getCode());
        List<User> v12MiningSzpnList = StreamUtils.filter(users, user -> v12LevelList.contains(user.getLevel()) || v12LevelList.contains(user.getNodeFlag()));
        //
        /*if (CollUtil.isNotEmpty(v12MiningSzpnList)) {
            BigDecimal everyAmount = NumberUtil.div(provincialAmount, v12MiningSzpnList.size());
            v12MiningSzpnList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    provincialAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }*/
        sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), provincialAmount));

        // v13
        BigDecimal nationalAmount = NumberUtil.mul(currentAmount, Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.v13.bonus.ratio")));
        List<Integer> v13LevelList = CollUtil.newArrayList(SzpnUserLevelEnum.V13.getCode(), SzpnUserLevelEnum.V14.getCode(), SzpnUserLevelEnum.V15.getCode());
        List<User> v13MiningSzpnList = StreamUtils.filter(users, user -> v13LevelList.contains(user.getLevel()) || v13LevelList.contains(user.getNodeFlag()));
        //
        /*if (CollUtil.isNotEmpty(v13MiningSzpnList)) {
            BigDecimal everyAmount = NumberUtil.div(nationalAmount, v13MiningSzpnList.size());
            v13MiningSzpnList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    nationalAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }*/
        sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), nationalAmount));

        // v14
        BigDecimal globalAmount = NumberUtil.mul(currentAmount, Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.v14.bonus.ratio")));
        List<Integer> v14LevelList = CollUtil.newArrayList(SzpnUserLevelEnum.V14.getCode(), SzpnUserLevelEnum.V15.getCode());
        List<User> v14MiningSzpnList = StreamUtils.filter(users, user -> v14LevelList.contains(user.getLevel()) || v14LevelList.contains(user.getNodeFlag()));
        //
        /*if (CollUtil.isNotEmpty(v14MiningSzpnList)) {
            BigDecimal everyAmount = NumberUtil.div(globalAmount, v14MiningSzpnList.size());
            v14MiningSzpnList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    globalAmount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }*/
        sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), globalAmount));

        // v15
        BigDecimal v15Amount = NumberUtil.mul(currentAmount, Convert.toBigDecimal(iSysConfigService.selectConfigByKey("biz.v15.bonus.ratio")));
        List<Integer> v15LevelList = CollUtil.newArrayList(SzpnUserLevelEnum.V15.getCode());
        List<User> v15MiningSzpnList = StreamUtils.filter(users, user -> v15LevelList.contains(user.getLevel()) || v15LevelList.contains(user.getNodeFlag()));
        //
        /*if (CollUtil.isNotEmpty(v15MiningSzpnList)) {
            BigDecimal everyAmount = NumberUtil.div(v15Amount, v15MiningSzpnList.size());
            v15MiningSzpnList.forEach(user -> {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        everyAmount,
                        TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                        null);
            });
        } else {
            userFoundServiceFacade.modifyUserFound(BONUS_ID,
                    null,
                    null,
                    UserFoundEnum.AVAILABLE_SZPN,
                    TransferFlagEnum.TRANSFER_IN,
                    v15Amount,
                    TransferDescEnum.MINING_BONUS_REWARD.getCode().toString(),
                    null);
        }*/
        sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), v15Amount));

        // 2、挖矿 - 按算力加权平分
        //BigDecimal afterRatio = NumberUtil.sub(1, bonus.getCityAgentRatio(), bonus.getProvincialAgentRatio(), bonus.getNationalAgentRatio(), bonus.getGlobalAgentRatio());
        BigDecimal mingAmount = NumberUtil.mul(currentAmount, new BigDecimal("0.9"));

        List<User> miningUserList = StreamUtils.filter(users, user -> user.getComputility().compareTo(BigDecimal.ZERO) > 0);

        String todayStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        List<UserFundDetail> userFundDetailList = userFundDetailMapper.selectList(Wrappers.<UserFundDetail>lambdaQuery().select(UserFundDetail::getUserId)
                .eq(UserFundDetail::getDescribes, TransferDescEnum.MINING_REWARD.getCode().toString())
                .eq(UserFundDetail::getTransferFlag, TransferFlagEnum.TRANSFER_IN.getCode())
                .eq(UserFundDetail::getType, UserFoundEnum.AVAILABLE_SZPN.getCode())
                .apply("DATE(create_time) = {0}", "2025-04-21"));

        Set<Long> existIds = StreamUtils.toSet(userFundDetailList, UserFundDetail::getUserId);
        miningUserList.forEach(user -> {
            BigDecimal amount = NumberUtil.mul(mingAmount, NumberUtil.div(user.getComputility(), globalComputility));

            if (!existIds.contains(user.getUserId())) {
                userFoundServiceFacade.modifyUserFound(user.getUserId(),
                        null,
                        null,
                        UserFoundEnum.AVAILABLE_SZPN,
                        TransferFlagEnum.TRANSFER_IN,
                        amount,
                        TransferDescEnum.MINING_REWARD.getCode().toString(),
                        null);
                sendTotalAmount.set(NumberUtil.add(sendTotalAmount.get(), amount));
            }
        });

        // 动态静态 扣除szpn
        /*userFoundServiceFacade.modifyUserFound(DYNAMIC_AND_STATIC_ID,
                null,
                null,
                UserFoundEnum.AVAILABLE_SZPN,
                TransferFlagEnum.TRANSFER_OUT,
                sendTotalAmount.get(),
                TransferDescEnum.DYNAMIC_AND_STATIC.getCode().toString(),
                null);*/

    }

    /**
     * 处理用户级别
     */
    public void handleSzpnUserLevel(List<Long> userIds) {
        List<User> userList = userMapper.selectList(Wrappers.<User>lambdaQuery().select(User::getUserId, User::getParentId, User::getUserLevel, User::getSelfAchievement, User::getTeamAchievement).in(CollUtil.isNotEmpty(userIds), User::getUserId, userIds));

        Map<Integer, SzpnConfig> szpnConfigMap = StreamUtils.toMap(szpnConfigMapper.selectList(), SzpnConfig::getUserLevel, Function.identity());

        List<User> allUserList = userMapper.selectList(Wrappers.<User>lambdaQuery().select(User::getUserId, User::getParentId, User::getUserLevel, User::getSelfAchievement, User::getTeamAchievement));
        List<User> updateUserList = CollUtil.newArrayList();
        for (User user : userList) {
            // 计算小区业绩
            List<User> directPushList = StreamUtils.filter(allUserList, u -> u.getParentId().equals(user.getUserId()));
            if (directPushList.size() < 2) {
                continue;
            }

            BigDecimal maxAchievement = BigDecimal.ZERO;
            BigDecimal totalAchievement = BigDecimal.ZERO;
            for (User directPushUser : directPushList) {
                BigDecimal directPushAchievement = NumberUtil.add(directPushUser.getSelfAchievement(), directPushUser.getTeamAchievement());
                if (directPushAchievement.compareTo(maxAchievement) > 0) {
                    maxAchievement = directPushAchievement;
                }
                totalAchievement = NumberUtil.add(totalAchievement, directPushAchievement);
            }
            BigDecimal minAchievement = NumberUtil.sub(totalAchievement, maxAchievement);

            if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            }  else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V6.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V6.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V7.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V7.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V6.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V6.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V8.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V8.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V7.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V7.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V6.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V6.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V9.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V9.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V8.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V8.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V7.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V7.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V6.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V6.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V10.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V10.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V9.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V9.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V8.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V8.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V7.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V7.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V6.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V6.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V11.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V11.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V10.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V10.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V9.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V9.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V8.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V8.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V7.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V7.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V6.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V6.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getInvestAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V12.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V12.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V11.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V11.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V10.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V10.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V9.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V9.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V8.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V8.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V7.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V7.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V6.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V6.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V13.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V13.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V12.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V12.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V11.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V11.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V10.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V10.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V9.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V9.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V8.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V8.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V7.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V7.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V6.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V6.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getInvestAmount()) >= 0 && user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getInvestAmount()) < 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V14.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V14.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V13.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V13.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V12.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V12.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V11.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V11.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V10.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V10.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V9.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V9.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V8.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V8.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V7.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V7.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V6.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V6.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            } else if (user.getSelfAchievement().compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getInvestAmount()) >= 0) {
                if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V15.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V15.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V15.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V14.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V14.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V14.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V13.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V13.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V13.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V12.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V12.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V12.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V11.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V11.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V11.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V10.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V10.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V10.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V9.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V9.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V9.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V8.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V8.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V8.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V7.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V7.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V7.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V6.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V6.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V6.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V5.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V5.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V5.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V4.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V4.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V4.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V3.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V3.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V3.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V2.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V2.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V2.getCode());
                        updateUserList.add(updateUser);
                    }
                } else if (minAchievement.compareTo(szpnConfigMap.get(SzpnUserLevelEnum.V1.getCode()).getMinAchievementAmount()) >= 0) {
                    if (user.getUserLevel() < SzpnUserLevelEnum.V1.getCode()) {
                        User updateUser =  new User();
                        updateUser.setUserId(user.getUserId());
                        updateUser.setUserLevel(SzpnUserLevelEnum.V1.getCode());
                        updateUserList.add(updateUser);
                    }
                }
            }

        }
        // 更新用户等级
        if (CollUtil.isNotEmpty(updateUserList)) {
            userMapper.updateBatchById(updateUserList);
        }

    }


}
